home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / Normal.cc,v < prev    next >
Text File  |  1989-02-20  |  2KB  |  132 lines

  1. head     3.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @@;
  7.  
  8.  
  9. 3.2
  10. date     89.02.20.15.36.20;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.1;
  13.  
  14. 3.1
  15. date     88.12.20.13.49.02;  author grunwald;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.10.30.13.03.14;  author grunwald;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     88.09.18.16.42.27;  author grunwald;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @@
  32.  
  33.  
  34. 3.2
  35. log
  36. @Start using Gnu library heaps for schedulers
  37. @
  38. text
  39. @// This may look like C code, but it is really -*- C++ -*-
  40. /* 
  41. Copyright (C) 1988 Free Software Foundation
  42.     written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
  43.  
  44. This file is part of GNU CC.
  45.  
  46. GNU CC is distributed in the hope that it will be useful,
  47. but WITHOUT ANY WARRANTY.  No author or distributor
  48. accepts responsibility to anyone for the consequences of using it
  49. or for whether it serves any particular purpose or works at all,
  50. unless he says so in writing.  Refer to the GNU CC General Public
  51. License for full details.
  52.  
  53. Everyone is granted permission to copy, modify and redistribute
  54. GNU CC, but only under the conditions described in the
  55. GNU CC General Public License.   A copy of this license is
  56. supposed to have been given to you along with GNU CC so you
  57. can know your rights and responsibilities.  It should be in a
  58. file named COPYING.  Among other things, the copyright notice
  59. and this notice must be preserved on all copies.  
  60. */
  61. #include <Normal.h>
  62.  
  63. //
  64. //    See Simulation, Modelling & Analysis by Law & Kelton, pp259
  65. //
  66. //    This is the ``polar'' method.
  67. // 
  68.  
  69. double Normal::operator()()
  70. {
  71.     
  72.     if (haveCachedNormal == 1) {
  73.     haveCachedNormal = 0;
  74.     return(cachedNormal * pStdDev + pMean );
  75.     } else {
  76.     
  77.     for(;;) {
  78.         double u1 = pGenerator -> asDouble();
  79.         double u2 = pGenerator -> asDouble();
  80.         double v1 = 2 * u1 - 1;
  81.         double v2 = 2 * u2 - 1;
  82.         double w = (v1 * v1) + (v2 * v2);
  83.         
  84. //
  85. //    We actually generate two IID normal distribution variables.
  86. //    We cache the one & return the other.
  87. // 
  88.         if (w <= 1) {
  89.         double y = sqrt( (-2 * log(w)) / w);
  90.         double x1 = v1 * y;
  91.         double x2 = v2 * y;
  92.         
  93.         haveCachedNormal = 1;
  94.         cachedNormal = x2;
  95.         return(x1 * pStdDev + pMean);
  96.         }
  97.     }
  98.     }
  99. }
  100.  
  101. @
  102.  
  103.  
  104. 3.1
  105. log
  106. @Steay version
  107. @
  108. text
  109. @@
  110.  
  111.  
  112. 1.2
  113. log
  114. @*** empty log message ***
  115. @
  116. text
  117. @@
  118.  
  119.  
  120. 1.1
  121. log
  122. @Initial revision
  123. @
  124. text
  125. @d36 1
  126. a36 1
  127.     return(cachedNormal * pVariance + pMean );
  128. d57 1
  129. a57 1
  130.         return(x1 * pVariance + pMean);
  131. @
  132.